// pages/dianzan/dianzan.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dianzanid:0,
    mun:0,
    uid:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var dianzanid = options.dianzanid;
    var that = this;
    if (dianzanid == undefined) {
      dianzanid = 0;
    }
    getApp().globalData.dianzanid = dianzanid;

    var userid = getApp().globalData.id;
    wx.request({
      url: 'https://wukongweixiu.cn/index/Defaults/getdianzan',
      data: {
        userid: userid,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        that.setData({
          mun: res.data.data
        })

      },
      fail: function (res) { },
      complete: function (res) { },
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  dianzan:function(){
    var that = this;
    var userid = getApp().globalData.id;
    var uid = that.data.dianzanid;
    if (uid == 0){
      wx.showModal({
        title: '不能为自己点赞',
        itemColor:"#ffffff"
      })
      return false;
    }
    wx.request({
      url: 'https://wukongweixiu.cn/index/Defaults/dianzan',
      data: { 
        userid: userid, 
        uid: uid
        },
      header: { 
        'content-type': 'application/x-www-form-urlencoded'
        },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        if (res.code == 1){
          wx.showModal({
            title: '点赞成功',
          })
        }else{
          wx.showModal({
            title: '您已点赞过了',
            itemColor: "#ffffff"
          })
        }
        
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  onShareAppMessage: function () {
    let page = this;
    let myInviteCode = page.data.id;
    if (myInviteCode) {

      let path = '/pages/dianzan/dianzan?dianzanid=' + myInviteCode;
      return {
        title: '悟空维修',
        path: path,
        imageUrl: 'https://wukongweixiu.cn/static/dianzan.png'
      }
    } else {
      // let path = '/pages/default/default?invite=7';
      return {
        title: '悟空维修',
        path: path,
        imageUrl: 'https://wukongweixiu.cn/static/dianzan.png' 
      }
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})